home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
kowin
/
archive
/
net
/
k20menus.lzh
/
k20input.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-12
|
15KB
|
664 lines
/* Copyright 1992 H.Ogasawara(COR.) */
#include <corlib.h>
#include <sys_doslib.h>
#define XO 4 /* window offset */
#define YO 4
#define HS (6*58) /* window size */
#define VS (15*15-6)
#define IOFF 4 /* title and box */
#define BOFF 1 /* box offset */
#define Ctrl(a) ((a)&0x1f)
#define DEBUG FALSE
extern char Yankbuf[];
extern attr;
char *pmenu[]= {
" Paste",
"設定登録",
"--------",
"設定削除",
"--------",
" 全消去",
"--------",
"設定取消",
};
#define MENUS (sizeof pmenu/sizeof(char*))
typedef struct {
short x, y;
short imax;
char *title;
} T_DIAG;
typedef struct {
char ibuf[40];
InputClass ip;
T_DIAG *tp;
char rs;
} T_IBUF;
T_DIAG tb[]= {
{ 0*6+XO, 0*15+YO, 8, "識別子(Key) " },
{ 26*6+XO, 0*15+YO, 6, "料金区域 " },
{ 44*6+XO, 0*15+YO, 6, "OPT " },
{ 0*6+XO, 1*15+YO,40, "ネット名 " },
{ 0*6+XO, 2*15+YO,40, "電話番号 " },
{ 0*6+XO, 3*15+YO,40, "ログファイル " },
{ 0*6+XO, 4*15+YO,40, "モデムコマンド" },
{ 0*6+XO, 5*15+YO,18, "アクセス手順1" },
{ 35*6+XO, 5*15+YO,18, ">" },
{ 0*6+XO, 6*15+YO,18, "アクセス手順2" },
{ 35*6+XO, 6*15+YO,18, ">" },
{ 0*6+XO, 7*15+YO,18, "アクセス手順3" },
{ 35*6+XO, 7*15+YO,18, ">" },
{ 0*6+XO, 8*15+YO,18, "アクセス手順4" },
{ 35*6+XO, 8*15+YO,18, ">" },
{ 0*6+XO, 9*15+YO,18, "アクセス手順5" },
{ 35*6+XO, 9*15+YO,18, ">" },
{ 0*6+XO,10*15+YO,18, "アクセス手順6" },
{ 35*6+XO,10*15+YO,18, ">" },
};
#define LN (sizeof tb/sizeof(T_DIAG))
/*
[ 9600]bps [8]bit [NonP] stop[1 ] SFlow[O] HFlow[O]漢字[SJIS]
識別子(Key) [00000000] 料金区域[市内 ] OPT[0 ]
ネット名 [ ]
電話番号 [ ]
ログファイル [ ]
モデムコマンド[ ]
アクセス手順1 [Command ][c denden\r ]
アクセス手順2 [--> ][\r ]
アクセス手順3 [> ][ID\r ]
アクセス手順4 [Passwd ][******\r ]
アクセス手順5 [ ][ ]
アクセス手順6 [ ][ ]
bps BIT パリティ STOP Sフロー Hフロー 漢字
[ | | | | | | ]
9600bps ビット長8 パリティナシ STOP 1 XON/OFF RTS/CTS SJIS
19200 ビット長7 パリティ偶 STOP1.5 なし なし 新JIS
38400 ビット長6 パリティ奇 STOP 2 EUC
旧JIS
NECJIS
全データ転送 取消 設定
*/
char *rs1[]={
" 38400 ",
" 19200 ",
"9600bps",
"4800bps",
"2400bps",
"1200bps",
" 600bps",
" 300bps",
" 150bps",
" 75bps",
},
*rs2[]={
"ビット長8",
"ビット長7",
"ビット長6",
"ビット長5",
},
*rs3[]={
"パリティナシ",
"パリティ偶",
"パリティ奇",
},
*rs4[]={
"STOP 1 ",
"STOP1.5",
"STOP 2 ",
},
*rs5[]={
"XON/OFF",
"Sフロー ナシ",
},
*rs6[]={
"RTS/CTS",
"Hフロー ナシ",
},
*rs7[]={
" S-JIS ",
" EUC ",
" 新JIS ",
" 旧JIS ",
"NEC-JIS",
};
char *ss1[]={
"38400",
"19200",
"9600",
"4800",
"2400",
"1200",
"600",
"300",
"150",
"75",
},
*ss2[]={
"8",
"7",
"6",
"5",
},
*ss3[]={
"N",
"E",
"O",
},
*ss4[]={
"1",
"1.5",
"2",
},
*ss5[]={
"X",
"N",
},
*ss6[]={
"ON",
"OFF",
},
*ss7[]={
"SJIS",
"EUC",
"JIS",
"JISO",
"NEC",
};
struct {
char **rs, **ss;
short len;
} rstbl[]= {
{ rs1, ss1, (sizeof rs1/sizeof(char*)) },
{ rs2, ss2, (sizeof rs2/sizeof(char*)) },
{ rs3, ss3, (sizeof rs3/sizeof(char*)) },
{ rs4, ss4, (sizeof rs4/sizeof(char*)) },
{ rs5, ss5, (sizeof rs5/sizeof(char*)) },
{ rs6, ss6, (sizeof rs6/sizeof(char*)) },
{ rs7, ss7, (sizeof rs7/sizeof(char*)) },
};
#define FONT 12
#define ATTR attr /*AttrDefault*/
#define BUFS 80
T_IBUF *tpi;
mod_netlist( tp, del )
T_IBUF *tp;
{
char lbuf[512];
ConsoleOpen();
if( !*tp->ibuf ){
ConsolePrint( "k20menu: Key が未設定です\r\n" );
return FALSE;
}
ConsolePrint( "k20menu:ファイル書き換え中\r\n" );
if( del )
*lbuf= '\0';
else
makelist( lbuf, tp );
if( !add_netlist( lbuf, tp->ibuf ) ){
ConsolePrint( "k20menu:ファイル書き換えに失敗しました\r\n" );
}else{
ConsolePrint( "k20menu:データを再読み込みしています\r\n" );
ReRead();
ConsolePrint( "k20menu:正常終了\r\n" );
}
return TRUE;
}
#if 0
f__open( file, tp, n, mode ) /* 0:add 1:mod 2:del */
unsigned char *file;
T_IBUF *tp;
{
#define SSIZE 512
FILE *fp;
unsigned char sbuf[SSIZE],
temp[80],
backup[80];
strcpy( temp, "a_$_bcde.tmp" );
strcpy( backup, "net_menu.bak" );
if( fp= fopen( file, "r" ) ){
FILE *fo;
if( fo= fopen( temp, "w" ) ){
for(; n-- && fgets( sbuf, SSIZE, fp ) ;)
fputs( sbuf, fo );
if( mode == 1 ){
makelist( sbuf, tp );
fputs( sbuf, fp );
putc( '\n', fp );
}
for(; fgets( sbuf, SSIZE, fp ) ;)
fputs( sbuf, fo );
fclose( fo );
fclose( fp );
RENAME( file, backup );
RENAME( temp, file );
return TRUE;
}
fclose( fp );
}
return FALSE;
}
#endif
char *
makers( str, tp )
unsigned char *str;
T_IBUF *tp;
{
int i;
*str= '"';
str[1]= '\0';
for( i= 0 ; i< 7 ; i++ ){
strcat( str, rstbl[i].ss[tp[i].rs] );
strcat( str, " " );
}
strcat( str, "\"" );
return str;
}
static unsigned char numtbl[LN+1]= {
0, 3, 4, 1, 5,99, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
makelist( str, tp )
unsigned char *str;
T_IBUF *tp;
{
char buf[80];
int i;
*str= '\0';
for( i= 0 ; i< LN+1 ; i++ ){
if( numtbl[i] == 99 ){
strcat( str, makers( buf, tp ) );
}else if( i && strchr( tp[numtbl[i]].ibuf, ' ' ) ){
strcat( str, "\"" );
strcat( str, tp[numtbl[i]].ibuf );
strcat( str, "\"" );
}else if( *tp[numtbl[i]].ibuf == '\0' && i < 8 ){
strcat( str, "\"\"" );
}else
strcat( str, tp[numtbl[i]].ibuf );
strcat( str, " " );
}
}
#define SY (12*15+16)
#define SALL (XO+6-2)
#define SCAN (XO+43*6-2)
#define SSET (XO+50*6-2)
DrawSetRS( dp, tp )
DrawBuf *dp;
T_IBUF *tp;
{
DrawBuf *dbuf= dp;
unsigned short i;
for( i= 0 ; i< 7 ; i++ ){
DrawSetSymbol( dp++, XO+i*8*6+2, SY-21,
rstbl[i].rs[tp[i].rs], ATTR, FONT );
DrawSetLine( dp++, XO+i*8*6-2+2, SY-23,
(i==6 ? 2:0)+ XO+i*8*6+42+1+2, SY-23+14,
ShadowDown, OptionShadow );
}
return dp-dbuf;
}
InputExec( wp, info )
WindowID wp;
EventInfo *info;
{
DrawBuf dbuf[LN*8+20],
*dp= dbuf;
T_IBUF *tp;
unsigned short i, j;
switch( info->option ){
case EventRedraw:
tp= WindowGetClientPointer(wp);
DrawSetClear( dp++, attr&AttrReverse?attr&3:0 );
for( i= 0 ; i< LN ; i++ ){
DrawSetSymbol( dp++, tb[i].x, tb[i].y, tb[i].title,
ATTR, FONT );
dp+= InputSetDraw( dp, &tp[i].ip );
DrawSetLine( dp++, tp[i].ip.x1-BOFF,
tp[i].ip.y1-BOFF,
tp[i].ip.x2+BOFF+7,
tp[i].ip.y2+BOFF,
ShadowDown, OptionShadow );
}
DrawSetSymbol( dp++, SALL+2, SY,
/* "全データ転送 追加 取消 書込",*/
"全データ転送 取消 登録",
ATTR, FONT );
DrawSetLine( dp++, SALL, SY-2, SALL+6*12+4, SY+14, ShadowUp, OptionShadow );
#if 1
DrawSetLine( dp++, SCAN, SY-2, SCAN+4*6+4, SY+14, ShadowUp, OptionShadow );
DrawSetLine( dp++, SSET, SY-2, SSET+4*6+4, SY+14, ShadowUp, OptionShadow );
#endif
DrawSetLine( dp++, XO, SY-6, tp[3].ip.x2+BOFF+7, SY+18, ShadowDown, OptionShadow );
dp+= DrawSetRS( dp, tp );
WindowDraw( wp, dbuf, dp-dbuf );
return TRUE;
case EventKey:
tp= WindowGetClientPointer(wp);
i= WindowGetClientData(wp);
WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &tp[i].ip, FALSE ) );
switch( info->KeyCode ){
case FuncKey+1:
i= 0;
break;
case FuncKey+2:
i= LN-1;
break;
case Ctrl('e'):
case Ctrl('p'):
case FuncKeyUp:
i= (i ? i : LN)-1;
break;
case Ctrl('x'):
case Ctrl('n'):
case FuncKeyDown:
case '\r':
case '\n':
if( ++i >= LN )
i= 0;
break;
case FuncKey+20:
info->option= EventClose;
WindowSendEvent( wp, info );
return TRUE;
case FuncKey+6:
return TRUE;
default:
WindowDraw( wp, dbuf, InputKey( dbuf, &tp[i].ip,
info->KeyCode, info->ShiftStat ) );
break;
}
WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &tp[i].ip, TRUE ) );
WindowSetClientData( wp, i, tp );
return TRUE;
case EventMouseSwitch:
tp= WindowGetClientPointer(wp);
i= WindowGetClientData(wp);
if( info->LeftON ){
static char *dummy[LN+3],
dmbuf[80];
if( info->x >= SALL && info->y >= SY-2 &&
info->x <= (SALL+6*12+4) && info->y <= SY+14 ){
makers( dmbuf, tp );
dummy[0]= "*";
dummy[1]= dmbuf;
dummy[LN+3-1]= NULL;
for( j= 0 ; j< LN ; j++ )
dummy[j+2]= tp[j].ibuf;
SendData( wp, info, UserStrings, dummy );
}else if( info->y >= SY-23 && info->y < SY-23+14 ){
*dmbuf= '*';
makers( dmbuf+1, tp );
SendData( wp, info, UserString, dmbuf );
#if 1
}else if( info->x >= SCAN && info->y >= SY-2 &&
info->x <= (SCAN+6*4+4) && info->y <= SY+14 ){
info->option= EventClose;
WindowSendEvent( wp, info );
return TRUE;
}else if( info->x >= SSET && info->y >= SY-2 &&
info->x <= (SSET+6*4+4) && info->y <= SY+14 ){
if( mod_netlist( tp, FALSE ) ){
info->option= EventClose;
WindowSendEvent( wp, info );
}
return TRUE;
/* char lbuf[512];
makelist( lbuf, tp );
add_netlist( lbuf, tp->ibuf );*/
#endif
}else for( j= 0 ; j< LN ; j++ ){
if( info->x >= tb[j].x &&
info->x <= tp[j].ip.x2+8 &&
info->y >= tb[j].y &&
info->y <= tp[j].ip.y2+2 ){
WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &tp[i].ip, FALSE ) );
WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &tp[i=j].ip, TRUE ) );
SendData( wp, info, UserString, tp[i].ibuf );
break;
}
}
}else if( info->RightON ){
int x, y;
char *p;
WindowGetScreenPosition( wp, &x, &y );
if( info->y >= SY-23 && info->y <= SY-23+14 ){
int code;
j= (info->x-XO)/(8*6);
if( j >= 7 )
return TRUE;
code= PopUpMenu( info->x+x-2, info->y+y+1,
rstbl[j].rs, rstbl[j].len, FONT );
if( code >= 0 ){
tp[j].rs= code;
DrawSetSymbol( dbuf, XO+j*8*6+2, SY-21,
rstbl[j].rs[tp[j].rs], ATTR, FONT );
/* DrawSetLine( dp++, XO+i*8*6-2+2, SY-23,
(i==6 ? 2:0)+ XO+i*8*6+42+1+2, SY-23+14,
ShadowDown, OptionShadow );*/
WindowDraw( wp, dbuf, 1 );
}
}else switch( PopUpMenu( x+info->x-2, y+info->y+1,
pmenu, MENUS, FONT ) ){
case 0:
if( p= WindowGetCommon( "Clip Board", 0 ) ){
info->option= EventUser;
info->ComData= UserPaste;
info->ComBuffer= p;
WindowSendEvent( wp, info );
break;
}
case 1: /* 変更 */
if( mod_netlist( tp, FALSE ) ){
info->option= EventClose;
WindowSendEvent( wp, info );
}
return TRUE;
case 3: /* 削除 */
makelist( Yankbuf, tp );
mod_netlist( tp, TRUE );
/* add_netlist( "", tp->ibuf );*/
break;
case 5:
for( j= 0 ; j< LN ; j++ ){
*tp[j].ibuf= '\0';
tp[j].ip.cur= 0;
tp[j].ip.curflag= FALSE;
tp[j].rs= 0;
}
i= 0;
tp[0].rs= 2;
tp[0].ip.curflag= TRUE;
WindowSetClientData( wp, i, tp );
WindowRedraw( wp );
return TRUE;
case 7:
info->option= EventClose;
WindowSendEvent( wp, info );
return TRUE;
}
}
WindowSetClientData( wp, i, tp );
return TRUE;
case EventIconify:
tp= WindowGetClientPointer(wp);
IconEnt( wp, *tp[3].ibuf ? tp[3].ibuf : "k20menu Input", ATTR, FONT );
return TRUE;
case EventOpen:
WindowSetClientData( wp, 0, tpi );
for( i= 0 ; i< LN ; i++ ){
#if DEBUG
*tpi[i].ibuf= '\0';
#endif
InputSet( &tpi[i].ip,
tb[i].x+strlen(tb[i].title)*6+IOFF,
tb[i].y,
tpi[i].ibuf, tb[i].imax, ATTR, FONT );
tpi[i].ip.curflag= FALSE;
tpi[i].ip.cur= strlen( tpi[i].ip.str );
/* tpi[i].rs= 0;*/
}
tpi->ip.curflag= FALSE;
WindowRedraw( wp );
WindowSetEventAttr( wp, EventOpenON|EventCloseON|EventRedrawON|
EventMouseSwitchON|EventIconifyON|EventUserON|
EventKeyON|EventMouseEnterON|EventMouseOutON );
return TRUE;
case EventClose:
tp= WindowGetClientPointer(wp);
WindowClose( wp );
free( tp );
#if DEBUG
WindowConnectionClose();
#endif
return TRUE;
case EventMouseEnter:
case EventMouseOut:
tp= WindowGetClientPointer(wp);
i= WindowGetClientData(wp);
WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &tp[i].ip,
info->option == EventMouseEnter ) );
return TRUE;
case EventUser:
switch( info->ComData ){
unsigned char *p, **pp;
case UserStrings:
pp= info->ComBuffer;
info->option= EventKey;
info->ShiftStat= 0;
if( *pp && **pp == '*' ){
info->KeyCode= FuncKey+1;
InputExec( wp, info );
if( *++pp ){
tp= WindowGetClientPointer(wp);
i= WindowGetClientData(wp);
rs2set( tp, *pp++ );
WindowDraw( wp, dbuf, DrawSetRS( dbuf, tp ) );
WindowSetClientData( wp, i, tp );
}
}
for(; *pp ;){
info->KeyCode= Ctrl('u');
InputExec( wp, info );
for( p= *pp++ ; *p ;){
info->KeyCode= *p++;
InputExec( wp, info );
}
info->KeyCode= '\r';
InputExec( wp, info );
}
break;
case UserString:
p= info->ComBuffer;
if( *p == '*' && p[1] == '"' ){
tp= WindowGetClientPointer(wp);
i= WindowGetClientData(wp);
rs2set( tp, p+1 );
WindowDraw( wp, dbuf, DrawSetRS( dbuf, tp ) );
WindowSetClientData( wp, i, tp );
break;
}
case UserPaste:
info->option= EventKey;
info->ShiftStat= 0;
for( p= info->ComBuffer ; *p ;){
info->KeyCode= *p++;
InputExec( wp, info );
}
break;
}
return TRUE;
}
return FALSE;
}
searchparam( tbl, key, n )
char **tbl;
char *key;
{
int i;
for( i= 0 ; i< n ; i++ ){
/*ConsolePrintf( "[%s][%s]\r\n", tbl[i], key );*/
if( !strcmp( tbl[i], key ) )
return i;
}
return -1;
}
rs2set( tp, p )
T_IBUF *tp;
char *p;
{
char bi[80];
int i, l;
if( *p == '"' ){
if( p[i= strlen(p)-1] == '"' )
p[i]= '\0';
p++;
}
for( i= 0 ; i< 7 ; i++ ){
p= (char*)getword( bi, p );
if( (l= searchparam( rstbl[i].ss, bi, rstbl[i].len ))>= 0 ){
tp[i].rs= l;
}else
tp[i].rs= 0;
}
}
OpenDiag( x, y, ptr )
char *ptr;
{
ConsoleOpen();
if( tpi= (T_IBUF*)malloc( LN*sizeof(T_IBUF) ) ){
memset( tpi, 0, LN*sizeof(T_IBUF) );
tpi[0].rs= 2;
if( *ptr ){
int i;
for( i= 0 ; i< LN+1 ; i++ ){
if( numtbl[i] == 99 ){
char buf[80];
ptr= (char*)getword( buf, ptr );
rs2set( tpi, buf );
}else{
ptr= (char*)getword( tpi[numtbl[i]].ibuf, ptr );
}
}
}
WindowTitleOpen( x, y, HS, VS, NULL, "Input", Close|Push|Icon,
InputExec);
}else{
ConsolePrint( "k20menu:malloc error.\r\n" );
#if DEBUG
WindowConnectionClose();
#endif
}
}
#if DEBUG
int WindowHeapSize= 20*1024;
WindowMain()
{
OpenDiag( 10, 10 );
}
#endif